package com.itheima.service;

import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Service implements UserDao{
    public User login(User user) {

        try {
            //获取核心配置文件
            InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
            //得到sessionFactory对象
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
            //获取Sqlsession对象
            SqlSession sqlSession = sessionFactory.openSession();

            UserDao mapper = sqlSession.getMapper(UserDao.class);
            return mapper.login(user);
        } catch (IOException e) {
            e.printStackTrace();
        }


        return null;
    }
}
